package com.steak.javassist;

import javassist.*;

import java.nio.charset.StandardCharsets;

/**
 * @author 刘牌
 * @Title:
 * @date 2022/3/2017:13
 */
public class JavassistApi {
    public static void main(String[] args) throws NotFoundException, CannotCompileException, InstantiationException, IllegalAccessException {
        ClassPool aDefault = ClassPool.getDefault();
        CtClass ctClass = aDefault.get("com.steak.javassist.UserService");
        CtMethod ctMethod = ctClass.getDeclaredMethod("getUser");
        ctMethod.insertAfter("System.out.print(\"sb\");");
        Class<UserService> aClass = ctClass.toClass();
        UserService userService = aClass.newInstance();
        userService.getUser();
    }
}
